import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import reportWebVitals from './reportWebVitals';

class ParentCom extends React.Component {
  constructor(props) {
    super(props)
    this.state ={}
  }
  // 渲染函数
  render() {
    // 返回视图模板
    return (
      <div>
        <form action="http://www.baidu.com">
          <div className="child">
            <h1 data-aa="1">hello world</h1>
            <button onClick={this.parentEvent}>提交</button>
          </div>
          <div>
            <button onClick={(e)=>{this.parentEvent1('123', e)}}>提交2</button>
            {/* 不使用ES6箭头函数传递多个参数的方式(需要绑定this) */}
            {/* <button onClick={function(e){this.parentEvent1('123', e)}.bind(this)}>提交2</button> */}
          </div>
        </form>
      </div>
    )
  }
  parentEvent = (e) => {
    console.log(e)
    console.log(e.target)
    // return false 不能阻止跳转
    console.log(e.preventDefault)
    e.preventDefault()
  }
  parentEvent1 = (params, e) => {
    console.log(params)
    console.log(e)
    e.preventDefault()
  }
}
ReactDOM.render(<ParentCom/>, document.getElementById('root'))
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
